#include "main/utils.h"
using namespace std;

int minCut(const string& s) {
  int length = s.size();
  vector<vector<bool>> isPal;
  isPal.resize(length);
  for (int i = 0; i < length; ++i) {
    isPal[i].resize(length, 0);
  }
  for (int i = 0; i < length; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (s[i] == s[j] && (i <= j + 1 || isPal[j + 1][i - 1])) {
        isPal[j][i] = 1;
      }
    }
  }

  vector<int> dp(length, INT_MAX);
  for (int i = 0; i < length; ++i) {
    if (isPal[0][i]) {
      dp[i] = 0;
    } else {
      for (int j = 1; j <= i; ++j) {
        if (isPal[j][i]) {
          dp[i] = min(dp[i], dp[j - 1] + 1);
        }
      }
    }
  }

  return dp[length - 1];
}

int main() {
  string s = "aaba";
  cout << minCut(s) << endl;

  return 0;
}
